<?php
namespace app\common\model;

class Account extends Base
{
	protected $pk = 'id';
	// protected $table = 'think_user';

    public static $status_txt = [
		1	=>	'正常',
		2	=>	'已禁用',
	];
	public static $role_txt = [
        0	=>	'超级管理员',
		1	=>	'销售',
		2	=>	'仓库',
		3	=>	'管理员',
		4	=>	'报单员',
		5	=>	'销售(报单)',
		6	=>	'管理员(团队)',
		7	=>	'客服(团队)',
	];
	// 定义需要追加的属性
    protected $append = ['role_names'];
	public function	accountMember()
    {
        return $this->hasMany('AccountMember','account_id');
    }
	// 关联角色
    public function roles()
    {
        return $this->belongsToMany(RoleModel::class, UserAttributesModel::class, 'role_id', 'user_id');
    }
    /**
     * 获取角色id
     * @Apidoc\Field("")
     * @Apidoc\AddField("role_ids", type="array", desc="角色id")
     */
    public function getRoleIdsAttr()
    {
        return relation_fields($this['roles'], 'role_id');
    }
	/**
     * 获取角色名称
     * @Apidoc\Field("")
     * @Apidoc\AddField("role_names", type="string", desc="角色名称")
     */
    public function getRoleNamesAttr()
    {
        return relation_fields($this['roles'], 'role_name', true);
    }
}